home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.6)
-
- '''Provides a graphical braille display at the top of the screen.
- This is mainly for debugging and for demonstrations.'''
- __id__ = '$Id: brlmon.py 3882 2008-05-07 18:22:10Z richb $'
- __version__ = '$Revision: 3882 $'
- __date__ = '$Date: 2008-05-07 14:22:10 -0400 (Wed, 07 May 2008) $'
- __copyright__ = 'Copyright (c) 2005-2008 Sun Microsystems Inc.'
- __license__ = 'LGPL'
- import gtk
- DOT_7 = '@'
- DOT_8 = '\x80'
- DOTS_78 = '\xc0'
- NORMAL = " size='xx-large'"
- CURSOR_CELL_EMPTY = " background='black'" + " weight='ultrabold'" + " style='italic'"
- CURSOR_CELL = " background='white'" + " weight='ultrabold'" + " style='italic'"
- ATTRIBUTE_7 = " underline='low'"
- ATTRIBUTE_8 = " underline='error'"
- ATTRIBUTE_78 = " underline='double'"
-
- class BrlMon(gtk.Window):
- """Displays a GUI braille monitor that mirrors what is being
- shown on the braille display. This currently needs a lot of
- work, but it is a start. TODO's include doing a better job of
- docking it at the top of the display (e.g., make all other
- windows move out from underneath it), doing better highlighting of
- the cursor cell, allowing the font to be set, and perhaps allowing
- clicks to simulate cursor routing keys."""
-
- def __init__(self, numCells = 32, cellWidth = 25, cellHeight = 50):
- '''Create a new BrlMon.
-
- Arguments:
- - numCells: how many braille cells to make
- - cellWidth: width of each cell in pixels
- - cellHeight: height of each cell in pixels
- '''
- gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)
- self.set_title('Braille Monitor')
- self.set_default_size(cellWidth * numCells, cellHeight)
- hbox = gtk.HBox(True)
- self.add(hbox)
- self.cellFrames = []
- self.cellLabels = []
- i = 0
- while i < numCells:
- frame = gtk.Frame()
- frame.set_shadow_type(gtk.SHADOW_OUT)
- label = gtk.Label(' ')
- label.set_use_markup(True)
- frame.add(label)
- hbox.add(frame)
- self.cellFrames.append(frame)
- self.cellLabels.append(label)
- i += 1
- self.set_property('accept-focus', False)
- self.connect_after('check-resize', self.onResize)
-
-
- def onResize(self, obj):
- '''Tell the window to be a dock and set its struts, which I
- thinks means to attempt to glue it somewhere on the display.
- '''
- screen_width = gtk.gdk.screen_width()
- (window_width, window_height) = self.window.get_size()
- if window_width < screen_width:
- x = (screen_width - window_width) / 2
- else:
- x = 0
- self.window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DOCK)
- self.window.property_change(gtk.gdk.atom_intern('_NET_WM_STRUT_PARTIAL', False), gtk.gdk.atom_intern('CARDINAL', False), 32, gtk.gdk.PROP_MODE_REPLACE, [
- 0,
- 0,
- window_height,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- screen_width - 1,
- 0,
- 0])
- self.move(x, 0)
-
-
- def writeText(self, cursorCell, string, mask = None):
- '''Display the given text and highlight the given
- cursor cell. A cursorCell of 0 means no cell has
- the cursor.
-
- Arguments:
- - cursorCell: 1-based index of cell with cursor
- - string: len must be <= num cells.
- '''
-
- try:
- string = string.decode('UTF-8')
- except:
- string = ''
-
- for i in range(0, len(string)):
- if string[i] == '<':
- char = '<'
- elif string[i] == '&':
- char = '&'
- elif string[i] == '\t':
- char = '$t'
- else:
- char = string[i]
- markup = NORMAL
- if i == cursorCell - 1:
- if string[i] == ' ':
- markup += CURSOR_CELL_EMPTY
- else:
- markup += CURSOR_CELL
- self.cellFrames[i].set_shadow_type(gtk.SHADOW_IN)
- else:
- self.cellFrames[i].set_shadow_type(gtk.SHADOW_OUT)
- if mask:
- if mask[i] == DOTS_78:
- markup += ATTRIBUTE_78
- elif mask[i] == DOT_7:
- markup += ATTRIBUTE_7
- elif mask[i] == DOT_8:
- markup += ATTRIBUTE_8
-
-
- self.cellLabels[i].set_markup('<span' + markup + '>%s</span>' % char)
-
- for i in range(len(string), len(self.cellFrames)):
- self.cellLabels[i].set_text(' ')
- self.cellFrames[i].set_shadow_type(gtk.SHADOW_OUT)
-
-
-
-